package com.love.labuladong.stack;

/**
 * 155.最小栈
 */
public class MinStack155 {

    public final int MAXN = 8001;

    public int[] data;

    public int[] min;

    int size;


    public MinStack155() {
        data = new int[MAXN];
        min = new int[MAXN];
        size = 0;
    }


    // 1）curVal <= min顶，curVal 压住 oldMin
    // 2)curVal > min顶，oldMin 压住 oldMin
    // 3）min 和 data 都为空，carVal 两栈都压
    public void push(int val) {
        data[size] = val;
        if(size == 0 || val <= min[size - 1]){
            min[size] = val;
        }else {
            min[size] = min[size - 1];
        }
        size++;
    }

    public void pop() {
        size--;
    }

    public int top() {
        return data[size - 1];
    }

    public int getMin() {
        return min[size - 1];
    }

}
